package com.ms.game.db.dto;

import com.ms.game.bank.db.BankLogModel;
import com.ms.game.bank.db.CashLogModel;
import com.ms.game.bank.message.SSimpleBankLog;
import com.ms.service.module.zone.message.SSimpleCashLog;
import com.xpec.c4.game.time.TimeSys;

/**
 * 交易明細 存摺類型的工具
 * @author TW16028
 *
 */
public class TransactionsDetailsUtil {
	
	/**cashlogmodel 每次傳給client限制 */
	public static final int TRANSACTION_DETAIL_TO_CLIENT_LIMIT = 10;
	
	/**30天的 milliseconds*/
	private static final long ONE_MONTH = 30 * 24 * 60 * 60 * 1000l;
	
	/**
	 *	CashLog
	 * 
	 * @param player
	 *            角色資料
	 * @return 回傳給 client 的cash log格式
	 */
	public static SSimpleCashLog CashLogModleToSimple(CashLogModel cashLogModel){
		SSimpleCashLog sl = new SSimpleCashLog();
	
		sl.eventDate = cashLogModel.getGameTime();
				
		sl.cashChangeValue = cashLogModel.getCashChangeValue();
		
		if(cashLogModel.getGoldChangeValue() == null){
			sl.goldChangeValue = "0.0";
		}
		else{
			sl.goldChangeValue = cashLogModel.getGoldChangeValue().toString();
		}
		
		if(cashLogModel.getChangeWay() < 0){
			sl.cashChangeValue = -sl.cashChangeValue;
		}
		
		sl.cashAfterChange = cashLogModel.getCashAfterChange();
		
		if(cashLogModel.getGoldAfterChange() == null){
			sl.goldAfterChange = "0.0";
		}
		else{
			sl.goldAfterChange = cashLogModel.getGoldAfterChange().toString();
		}
			
		sl.changeWay = cashLogModel.getChangeWay();
		
		//目前沒有規劃
		sl.remark = "";
		
		return sl;
	}
	
	
	public static SSimpleBankLog BankLogModelToSimple(BankLogModel bankLogModel){
		
		SSimpleBankLog sl = new SSimpleBankLog();
		
		sl.eventDate = bankLogModel.getGameTime();
	
		sl.downlineName = bankLogModel.getDownlineName();
		
		sl.bankGoldAfterChange = bankLogModel.getBankGoldAfterChange().toString();
		
		sl.bankGoldChangeValue = bankLogModel.getBankGoldChangeValue().toString();
		
		sl.belongsDate = bankLogModel.getRebateDate() == null ? 0 : bankLogModel.getRebateDate().getTime();
	
		sl.changeWay = bankLogModel.getChangeWay();
		
		return sl;
	}
	
	
	public static long checkTransactionDateRange(long time){
		long today = TimeSys.currentTimeMills();
		long endDay = today - ONE_MONTH;
		
		if(time < endDay)
			return endDay;
		else
			return time;
	} 

}
